import React, { Component } from 'react'
import AddCounter from './AddCounter'
import SubCounter from './SubCounter'

export class App extends Component {
  constructor() {
    super()
    this.state = {
      counter: 100,
    }
  }

  addClick(count) {
    this.setState({
      counter: this.state.counter + count,
    })
  }

  subClick(count) {
    this.setState({
      counter: this.state.counter - count,
    })
  }

  render() {
    const { counter } = this.state

    return (
      <div className="app">
        <h2>当前计数：{counter}</h2>
        <AddCounter addClick={(count) => this.addClick(count)} />
        <SubCounter subClick={(count) => this.subClick(count)} />
      </div>
    )
  }
}

export default App
